package com.ytrsoft.task;

import com.ytrsoft.bean.Message;
import com.ytrsoft.ws.IdeaSocket;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class InputHandler extends ExecutorHandler implements ActionHandler {

    private final IdeaSocket socket;

    private final ExecutorService executor = Executors.newSingleThreadExecutor();

    public InputHandler(IdeaSocket socket) {
        this.socket = socket;
    }

    @Override
    public void doMessage(Message msg) {
        start(msg);
    }

    @Override
    protected void running(Message msg) {
        String s = System.lineSeparator();
        socket.getStdIn().appendData(msg.getBody() + s);
    }


    @Override
    public void destroy() {
        killNow();
    }

}
